<template>
	<view class="content flex-column  bg-white">
		<view class="scroll-y  flex-grow" hover-class="none" hover-stop-propagation="false">
			<view class="flex justify-center mb-xl">
				<view class="img-bg flex align-center justify-center bg-theme-lightest radius-circle">
					<image class="img-logo" src="/static/logo.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="flex-column justify-center align-center">
				<view class="text-xxl font-bold">
					{{ appConfig.appName }}
				</view>
				<view class="text-placeholder mt-base text-base">
					您的个人健康管家
				</view>
			</view>
			<button open-type="getPhoneNumber" @getphonenumber="login"
				class="mx-xl mb-xl linear-bg-norml text-inverse btn-login text-xl flex align-center justify-center shadow-lg"
				hover-class="button_hover">
				<text class="cus-icon cus-icon-Key mr-md text-xxl"></text>
				<text>一键快速登录</text>
			</button>
			<view class="flex justify-center align-center text-base">
				<text>登录即表示用户同意</text>
				<text class="text-theme">用户协议</text>
				<text class="mx-xs">和</text>
				<text class="text-theme">隐私政策</text>
			</view>
		</view>
	</view>
</template>

<script>
import CustomTabbarVue from '@/components/CustomTabbar.vue';
import {
	mapGetters
} from 'vuex'
export default {
	components: {
		CustomTabbarVue
	},
	computed: {
		...mapGetters({
			appConfig: 'app/appConfig'
		})
	},
	data() {
		return {
			returnURL: '',
			scene: ''
		}
	},
	onLoad(option) {
		this.init(option)
	},
	methods: {
		init(option) {
			let returnURL = decodeURIComponent(option.returnURL || '');
			let scene = decodeURIComponent(option.scene || '');
			this.returnURL = returnURL || ''
			this.scene = scene || ''
		},
		login(e) {
			if (e.detail && e.detail.code) {
				console.error(e.detail.code)
			}

		},
		wxLogin() {
			// 创建用户信息对象
			const userInfo = {
				phoneNumber: '111111',
				WeiXinId: 'o3_ix6whQhZM75buago851od2_HU'
			}

			// 创建模拟的token (实际应用中通常从服务器获取)
			const token = 'mock-token-' + Date.now()

			// 调用store的登录action
			this.$store.dispatch('user/login', {
				token,
				userInfo
			})

			// 登录成功后的处理
			const returnUrl = this.returnURL || '/pages/index/index'
			uni.switchTab({
				url: returnUrl,
				success: () => {
					console.log('登录成功，已跳转到：', returnUrl)
				}
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.img-bg {
	margin-top: 30vh;
	width: $uni-img-size-lg*3.6;
	height: $uni-img-size-lg*3.6;

	.img-logo {
		width: $uni-img-size-lg*3;
		height: $uni-img-size-lg*3;
	}
}

.btn-login {

	border-radius: $uni-border-radius-base*10;
	margin-top: $uni-spacing-col-base*5;
}
</style>